import { connect } from 'react-redux';
import reducer, { getDetail, getTypes } from '../store/detail';
import purchaseReducer, {
  reserverInfo,
  clearReverseInfo
} from '../store/purchase';
import { injectReducer } from '../store/reducers';
import { withRouter } from 'react-router-dom';
import store from '../store/createStore';
import HeadInfo from '../components/detail/HeadInfo';

const mapDispatchToProps = {
  getDetail,
  getTypes,
  reserverInfo,
  clearReverseInfo
};

const mapStateToProps = state => ({
  baseInfo: state.detail.baseInfo,
  types: state.detail.types,
  priceRange: state.detail.priceRange,
  logged: state.user.logged
});

injectReducer(store, { key: 'detail', reducer });
injectReducer(store, { key: 'purchase', purchaseReducer });

export default withRouter(
  connect(
    mapStateToProps,
    mapDispatchToProps
  )(HeadInfo)
);
